﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.WoWInternals;
using ObjectManager = Styx.WoWInternals.ObjectManager;

namespace ProfileChangerII
{
    class ProfileChangerSettings
    {

        string File = "Plugins\\ProfileChangerII\\config\\";
        public ProfileChangerSettings()
        {
            if (ObjectManager.Me != null)
                try
                {
                    Load();
                }
                catch (Exception e)
                {
                    Logging.Write(System.Drawing.Color.Red, e.Message);
                }
        }

        public bool UseMin = true;
        public bool UseLvl = false;
		
		public bool Active1 = false;
        public bool Active2 = false;
        public bool Active3 = false;
        public bool Active4 = false;
        public bool Active5 = false;
        public bool Active6 = false;
		public bool Active7 = false;
        public bool Active8 = false;
        public bool Active9 = false;
        public bool Active10 = false;
        public bool Active11 = false;
        public bool Active12 = false;
		
        public string Profile1 = "";
        public string Profile2 = "";
        public string Profile3 = "";
        public string Profile4 = "";
        public string Profile5 = "";
        public string Profile6 = "";
		public string Profile7 = "";
        public string Profile8 = "";
        public string Profile9 = "";
        public string Profile10 = "";
        public string Profile11 = "";
        public string Profile12 = "";
		
        public string Minutes1 = "0";
        public string Minutes2 = "0";
        public string Minutes3 = "0";
        public string Minutes4 = "0";
        public string Minutes5 = "0";
        public string Minutes6 = "0";
		public string Minutes7 = "0";
        public string Minutes8 = "0";
        public string Minutes9 = "0";
        public string Minutes10 = "0";
        public string Minutes11 = "0";
        public string Minutes12 = "0";
		
		public string Portal1 = "";
        public string Portal2 = "";
        public string Portal3 = "";
        public string Portal4 = "";
        public string Portal5 = "";
        public string Portal6 = "";
		public string Portal7 = "";
        public string Portal8 = "";
        public string Portal9 = "";
        public string Portal10 = "";
        public string Portal11 = "";
        public string Portal12 = "";
		
        public bool Heart1 = false;
        public bool Heart2 = false;
        public bool Heart3 = false;
        public bool Heart4 = false;
        public bool Heart5 = false;
        public bool Heart6 = false;
        public bool Heart7 = false;
        public bool Heart8 = false;
        public bool Heart9 = false;
        public bool Heart10 = false;
        public bool Heart11 = false;
        public bool Heart12 = false;
       
        public bool StopBot = false;
		
		// -------------- Load ConfigFile ---------------
        public void Load()
        {
            //    XmlTextReader reader;
            XmlDocument xml = new XmlDocument();
            XmlNode xvar;

            string sPath = Process.GetCurrentProcess().MainModule.FileName;
            sPath = Path.GetDirectoryName(sPath);
            sPath = Path.Combine(sPath, File);

            if (!Directory.Exists(sPath))
            {
                Logging.WriteDebug("Profile Changer: Creating config directory");
                Directory.CreateDirectory(sPath);
            }

            sPath = Path.Combine(sPath, "ProfileChangerII.config");

            Logging.WriteDebug("Profile Changer: Loading config file: {0}", sPath);
            System.IO.FileStream fs = new System.IO.FileStream(@sPath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
            try
            {
                xml.Load(fs);
                fs.Close();
            }
            catch (Exception e)
            {
                Logging.WriteDebug(e.Message);
                Logging.Write("Profile Changer: Continuing with Default Config Values");
                fs.Close();
                return;
            }

            //            xml = new XmlDocument();

            try
            {
                //                xml.Load(reader);
                if (xml == null)
                    return;
                // Load Variables
                xvar = xml.SelectSingleNode("//ProfileChangerII/UseMinutes");
                if (xvar != null)
                {
                    UseMin = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + UseMin.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/UseLevel");
                if (xvar != null)
                {
                    UseLvl = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + UseLvl.ToString());
                }

                xvar = xml.SelectSingleNode("//ProfileChangerII/Active1");
                if (xvar != null)
                {
                    Active1 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active1.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Profile1");
                if (xvar != null)
                {
                    Profile1 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile1.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes1");
                if (xvar != null)
                {
                    Minutes1 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes1.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart1");
                if (xvar != null)
                {
                    Heart1 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart1.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal1");
                if (xvar != null)
                {
                    Portal1 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal1.ToString());
                }

				
				xvar = xml.SelectSingleNode("//ProfileChangerII/Active2");
                if (xvar != null)
                {
                    Active2 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active2.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Profile2");
                if (xvar != null)
                {
                    Profile2 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile2.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes2");
                if (xvar != null)
                {
                    Minutes2 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes2.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart2");
                if (xvar != null)
                {
                    Heart2 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart2.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal2");
                if (xvar != null)
                {
                    Portal2 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal2.ToString());
                }

				
				xvar = xml.SelectSingleNode("//ProfileChangerII/Active3");
                if (xvar != null)
                {
                    Active3 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active3.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Profile3");
                if (xvar != null)
                {
                    Profile3 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile3.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes3");
                if (xvar != null)
                {
                    Minutes3 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes3.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart3");
                if (xvar != null)
                {
                    Heart3 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart3.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal3");
                if (xvar != null)
                {
                    Portal3 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal3.ToString());
                }

				
				xvar = xml.SelectSingleNode("//ProfileChangerII/Active4");
                if (xvar != null)
                {
                    Active4 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active4.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Profile4");
                if (xvar != null)
                {
                    Profile4 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile4.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes4");
                if (xvar != null)
                {
                    Minutes4 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes4.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart4");
                if (xvar != null)
                {
                    Heart4 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart4.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal4");
                if (xvar != null)
                {
                    Portal4 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal4.ToString());
                }

				
				xvar = xml.SelectSingleNode("//ProfileChangerII/Active5");
                if (xvar != null)
                {
                    Active5 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active5.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Profile5");
                if (xvar != null)
                {
                    Profile5 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile5.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes5");
                if (xvar != null)
                {
                    Minutes5 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes5.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart5");
                if (xvar != null)
                {
                    Heart5 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart5.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal5");
                if (xvar != null)
                {
                    Portal5 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal5.ToString());
                }

				
				xvar = xml.SelectSingleNode("//ProfileChangerII/Active6");
                if (xvar != null)
                {
                    Active6 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active6.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Profile6");
                if (xvar != null)
                {
                    Profile6 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile6.ToString());
                }
				xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes6");
                if (xvar != null)
                {
                    Minutes6 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes6.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart6");
                if (xvar != null)
                {
                    Heart6 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart6.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal6");
                if (xvar != null)
                {
                    Portal6 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal6.ToString());
                }


                xvar = xml.SelectSingleNode("//ProfileChangerII/Active7");
                if (xvar != null)
                {
                    Active7 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active7.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Profile7");
                if (xvar != null)
                {
                    Profile7 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile7.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes7");
                if (xvar != null)
                {
                    Minutes7 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes7.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart7");
                if (xvar != null)
                {
                    Heart7 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart7.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal7");
                if (xvar != null)
                {
                    Portal7 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal7.ToString());
                }


                xvar = xml.SelectSingleNode("//ProfileChangerII/Active8");
                if (xvar != null)
                {
                    Active8 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active8.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Profile8");
                if (xvar != null)
                {
                    Profile8 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile8.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes8");
                if (xvar != null)
                {
                    Minutes8 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes8.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart8");
                if (xvar != null)
                {
                    Heart8 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart8.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal8");
                if (xvar != null)
                {
                    Portal8 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal8.ToString());
                }


                xvar = xml.SelectSingleNode("//ProfileChangerII/Active9");
                if (xvar != null)
                {
                    Active9 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active9.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Profile9");
                if (xvar != null)
                {
                    Profile9 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile9.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes9");
                if (xvar != null)
                {
                    Minutes9 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes9.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart9");
                if (xvar != null)
                {
                    Heart9 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart9.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal9");
                if (xvar != null)
                {
                    Portal9 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal9.ToString());
                }


                xvar = xml.SelectSingleNode("//ProfileChangerII/Active10");
                if (xvar != null)
                {
                    Active10 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active10.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Profile10");
                if (xvar != null)
                {
                    Profile10 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile10.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes10");
                if (xvar != null)
                {
                    Minutes10 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes10.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart10");
                if (xvar != null)
                {
                    Heart10 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart10.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal10");
                if (xvar != null)
                {
                    Portal10 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal10.ToString());
                }


                xvar = xml.SelectSingleNode("//ProfileChangerII/Active11");
                if (xvar != null)
                {
                    Active11 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active11.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Profile11");
                if (xvar != null)
                {
                    Profile11 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile11.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes11");
                if (xvar != null)
                {
                    Minutes11 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes11.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart11");
                if (xvar != null)
                {
                    Heart11 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart11.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal11");
                if (xvar != null)
                {
                    Portal11 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal11.ToString());
                }


                xvar = xml.SelectSingleNode("//ProfileChangerII/Active12");
                if (xvar != null)
                {
                    Active12 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Active12.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Profile12");
                if (xvar != null)
                {
                    Profile12 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Profile12.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Minutes12");
                if (xvar != null)
                {
                    Minutes12 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Minutes12.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Heart12");
                if (xvar != null)
                {
                    Heart12 = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Heart12.ToString());
                }
                xvar = xml.SelectSingleNode("//ProfileChangerII/Portal12");
                if (xvar != null)
                {
                    Portal12 = Convert.ToString(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + Portal12.ToString());
                }


                xvar = xml.SelectSingleNode("//ProfileChangerII/StopBot");
                if (xvar != null)
                {
                    StopBot = Convert.ToBoolean(xvar.InnerText);
                    Logging.WriteDebug("Profile Changer Load: " + xvar.Name + "=" + StopBot.ToString());
                }
			}
            catch (Exception e)
            {
                Logging.WriteDebug("Profile Changer: PROJECTE EXCEPTION, STACK=" + e.StackTrace);
                Logging.WriteDebug("Profile Changer: PROJECTE EXCEPTION, SRC=" + e.Source);
                Logging.WriteDebug("Profile Changer: PROJECTE : " + e.Message);
            }
		}
    }
}
